/*******************************************************************************
 * Copyright (c) 2011 Bruno Quoitin.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Bruno Quoitin - initial API and implementation
 ******************************************************************************/
package Message;

import java.util.UUID;

import reso.common.Message;
import reso.ip.IPAddress;
import DSRStructure.DSRRoutingEntry;


public abstract class DSRMessage
implements Message {

	public static enum Type {
		RREQ, RREP, PayLoad, ERROR
	}
	
	protected UUID id;
	protected Type type;
	protected IPAddress ipAddrDest;
	protected DSRRoutingEntry route;
	
	protected DSRMessage(Type type, IPAddress ipAddress) {
		this.id = UUID.randomUUID();
		this.type= type;
		this.ipAddrDest= ipAddress;
		this.route= new DSRRoutingEntry();
	}
	
	protected DSRMessage(Type type, IPAddress ipAddress, DSRRoutingEntry route) {
		this.id = UUID.randomUUID();
		this.type= type;
		this.ipAddrDest= ipAddress;
		this.route= route;
	}
	
	protected DSRMessage() {
		this.id = UUID.randomUUID();
		this.type= Type.ERROR;
		this.ipAddrDest= null ;
		this.route= new DSRRoutingEntry();
	}

	public void addadr( IPAddress new_addr ) {
		route.addAddressEntry(new_addr) ;
	}

	
	public UUID getId() {
		return id;
	}

	public Type getType() {
		return type;
	}

	public IPAddress getIpAddrDest() {
		return ipAddrDest;
	}

	public DSRRoutingEntry getRoute() {
		return route;
	}

	public void setRoute(DSRRoutingEntry route) {
		this.route = route;
	}
	
	
	public String toString() {
		String s= "type=" + type + ", ID = " + id + ", ip_search=" + ipAddrDest + " route :["+ route.toString()+"]";
		
	/*	for (int i = 0 ; i < listAdress.size(); i++ ) {
			s = s + "\n" + "adressentry : " + i + " ==> " + listAdress.get(i).toString() ;
		}*/
		return s;
	}
	
}
